/**
 *　　　　　　　　┏┓　　　┏┓+ +
 *　　　　　　　┏┛┻━━━┛┻┓ + +
 *　　　　　　　┃　　　　　　　┃ 　
 *　　　　　　　┃　　　━　　　┃ ++ + + +
 *　　　　　　 ████━████ ┃+
 *　　　　　　　┃　　　　　　　┃ +
 *　　　　　　　┃　　　┻　　　┃
 *　　　　　　　┃　　　　　　　┃ + +
 *　　　　　　　┗━┓　　　┏━┛
 *　　　　　　　　　┃　　　┃　　　　　　　　　　　
 *　　　　　　　　　┃　　　┃ + + + +
 *　　　　　　　　　┃　　　┃　　　　Code is far away from bug with the animal protecting　　　　　　　
 *　　　　　　　　　┃　　　┃ + 　　　　神兽保佑,代码无bug　　
 *　　　　　　　　　┃　　　┃
 *　　　　　　　　　┃　　　┃　　+　　　　　　　　　
 *　　　　　　　　　┃　 　　┗━━━┓ + +
 *　　　　　　　　　┃ 　　　　　　　┣┓
 *　　　　　　　　　┃ 　　　　　　　┏┛
 *　　　　　　　　　┗┓┓┏━┳┓┏┛ + + + +
 *　　　　　　　　　　┃┫┫　┃┫┫
 *　　　　　　　　　　┗┻┛　┗┻┛+ + + +
 */

if(document.body.clientWidth < 800){ //is Mobile?
    alert('您的显示设备可能不满足程序的最低要求, 请更换设备后再继续浏览 \n 程序终止运行!');
    var el = document.getElementsByTagName('body')[0];
    el.parentNode.removeChild(el);
    throw new Error('喵喵喵?');
}
if (!!window.ActiveXObject || "ActiveXObject" in window) { //is IE?
    alert('为了更好的使用体验, 建议使用新版本的浏览器继续浏览');
    window.open('http://outdatedbrowser.com/zh-cn')
}
if(navigator.userAgent.toLowerCase().indexOf("ucbrowser") > 0){ //is UC?
    alert('系统检测到您使用了UC浏览器, 由于UC浏览器使用了极旧的内核, 可能在使用过程中出现问题, \n 为了您的更好体验, 建议使用新版本的浏览器继续浏览');
    window.open('http://outdatedbrowser.com/zh-cn')
}

var textareaData,
    //接口设置
    interface = {
        statistics: '../queryStatics', // 信息统计
        newsList: { // 新闻列表
            searchNews:'../searchNews', //搜索新闻
            getNews: '../searchAllNews', //获取全部新闻
            delNews: '../deleteNews', //删除新闻
            addNews: '../addNews'//添加新闻或者修改新闻
        },
        doctors: { //医生展示管理页面
            searchDoctor:'../searchDoctors', //搜索医生
            getDoctorList: '../getDoctorList', //获取全部医生
            deldoctors: '../deldoctors', //删除医生
            adddoctors: '../addDoctors' //添加医生
        },
        homeManagement: { //首页轮播图管理
            getImg: '../getImgs', //获取全部轮播图
            delImg: '../delImgs', //删除轮播图
            addImg: '../addImgs' //添加轮播图
        },
        infoList: { // 医院介绍页面
            searchInfo: '', //搜索医院介绍
            getInfo: '../json/infoList.json', //获取全部医院介绍
            delInfo: '', //删除医院介绍
            addInfo: '' //添加医院介绍
        },
        addGoods: { // 添加商品页面
            imgUpload: '', //图片上传
            addGoods: '', //添加商品
            getGoods: '../json/getgoods.json' //获取全部商品
        },
        goodsManagement: { //商品管理页面
            searchGoods: '', //搜索商品页面
            getGoods: '../json/goodsManagement.json', //获取某个商品信息
            delGoods: '', //删除商品
        },
        orderView: { //订单查看页面
            searchOrder: '', //搜索订单
            getOrder: '../json/orderView.json' //获取全部订单
        },
        orderAudit: { //退款审核页面
            searchOrder: '', //搜索订单
            getOrder: '../json/orderAudit.json', //获取全部订单
            audit: '' //订单审核
        },
        finance: { // 财务管理页面
            searchFinance: '', //搜索订单
            getFinance: '../json/finance.json', //获取全部订单
            statistics: '../json/Fstatistics.json' //
        },
        userManagement: { // 用户管理页面
            searchUser: '', //搜索用户
            getUser: '../json/userManagement.json', //获取全部用户
            getUserOrderList: '../json/UserOrderList.json', //获取某个用户的全部订单信息
            sendMessage: '' //发送全体公告
        },
        textEditorImgUpdate: '../update.do', //编辑器图片上传页面
        signOut: '' //退出登录
    },
    nya = {
        // 启用pjax
        PJAX: function () {
            $(document).on('click', 'a[data-pjax]', function (e) {
                e.preventDefault();
                $.pjax({
                    url: this.href,
                    type: 'GET',
                    dataType: 'html',
                    fragment: '#nya',
                    container: '#nya',
                    timeout: 8000,
                })
            }).on('pjax:send', function () {
                NProgress.start();
            }).on('pjax:complete', function () {
                NProgress.done();
                nya.PJAXFUN();
            }).on('pjax:popstate', function () {
                setTimeout(function () {
                    nya.PJAXFUN();
                }, 300)
            })
        },
        // 表格兼容pjax
        tableReset: function(){
            TableSet = {};
            CheckData = {};
            GetJSONData = {};
        },
        // 每次 pjax 刷新页面都需要执行的方法
        PJAXFUN: function () {
            nya.TEXTAREA();
            nya.SIDEBARHOVER();
            nya.statistics();
            nya.newsList();
            nya.homeManagement();
            nya.infoList();
            nya.doctors();
            nya.addGoods();
            nya.goodsManagement();
            nya.orderView();
            nya.orderAudit();
            nya.finance();
            nya.userManagement();
        },

        // json to csv
        JSONToCSVConvertor: function(JSONData, ReportTitle, ShowLabel) {
            //If JSONData is not an object then JSON.parse will parse the JSON string in an Object
            var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
            var CSV = '';    
            //This condition will generate the Label/Header
            if (ShowLabel) {
                var row = "";

                //This loop will extract the label from 1st index of on array
                for (var index in arrData[0]) {
                    //Now convert each value to string and comma-seprated
                    row += index + ',';
                }
                row = row.slice(0, -1);
                //append Label row with line break
                CSV += row + '\r\n';
            }

            //1st loop is to extract each row
            for (var i = 0; i < arrData.length; i++) {
                var row = "";
                //2nd loop will extract each column and convert it in string comma-seprated
                for (var index in arrData[i]) {
                    row += '"' + arrData[i][index] + '",';
                }
                row.slice(0, row.length - 1);
                //add a line break after each row
                CSV += row + '\r\n';
            }

            if (CSV == '') {        
                alert("Invalid data");
                return;
            }   

            //this trick will generate a temp "a" tag
            var link = document.createElement("a");    
            link.id="lnkDwnldLnk";

            //this part will append the anchor tag and remove it after automatic click
            document.body.appendChild(link);

            var csv = CSV;  
            blob = new Blob([csv], { type: 'text/csv,charset=UTF-8' }); 
            var csvUrl = window.URL.createObjectURL(blob);
            var filename = 'UserExport.csv';
            $("#lnkDwnldLnk")
            .attr({
                'download': filename,
                'href': csvUrl
            }); 

            $('#lnkDwnldLnk')[0].click();    
            document.body.removeChild(link);
        },

        // 后台面板设置
        ADMIN: function(){
            $('.user .list li').eq(0).click(function (e) { 
                e.preventDefault();
                $.ajax({
                    type: "GET",
                    url: interface.signOut,
                    dataType: "json",
                    success: function (response) {
                        if(response.error == 0){
                            layer.msg('退出登录成功');
                        }
                    }
                });
            });
            $('.user .list li').eq(1).click(function (e) { 
                e.preventDefault();
                layer.open({
                    title:'关于程序',
                    area: ['400px', '400px'],
                    move:'#LayWindow,.layui-layer-title',
                    moveOut : true,
                    type: 1, 
                    content: '<div id="LayWindow"></div><div class="layerCon"><div class="about"><p>这里是关于程序</p></div></div>'
                });
            });
        },

        // 侧边栏列表的选中效果
        SIDEBARHOVER: function () {
            $('.admin-sidebar .hover').removeClass('hover');
            var className = $('.admin-body .content > div').attr('class'),
                node = $('#' + className),
                list2 = $(node).parents('.list2'),
                listLength = list2.find('li').length
            $(node).addClass('hover');
            $(list2).height(list2.height(listLength * 50))
            $(list2).siblings('a').find('.expand').css('transform', 'rotate(180deg)');
        },
        // 首次加载动画
        LOADING: function () {
            $(window).load(function () {
                setTimeout(function () {
                    jQuery("#loading").fadeOut(500);
                }, 300)

            })
        },
        // 侧边栏
        SIDEBAR: function () {
            var timeout;
            $('.admin-sidebar .list > li').hover(function () {
                if (timeout) {
                    clearTimeout(timeout)
                }
                var newTop = $(this).offset().top - 60;
                $('.checked-border').css({
                    'top': newTop,
                    'left': 0
                });
            }, function () {
                timeout = setTimeout(function () {
                    $('.checked-border').css('left', -5);
                }, 500)
            })

            $('.admin-sidebar .list > li > a').click(function (e) {
                e.preventDefault();
                var list2 = $(this).siblings('ul.list2'),
                    listLength = list2.find('li').length;
                if (list2.length > 0) {
                    if (list2.height() == 0) {
                        list2.height(listLength * 50);
                        $(this).find('.expand').css('transform', 'rotate(180deg)');
                    } else {
                        list2.height(0);
                        $(this).find('.expand').css('transform', 'rotate(0deg)');
                    }
                }
            });
        },
        // 头部
        HEADERBAR: function () {
            $('.admin-header .user').hover(function (e) {
                e.preventDefault();
                $(this).height(175);
                $('.admin-header .list').stop().slideToggle(250);
            }, function () {
                $(this).height('auto');
                $('.admin-header .list').stop().slideToggle(250);
            });
        },
        // 富文本编辑器
        TEXTAREA: function () {
            if ($('.textarea').length > 0) {
                $('.textarea').html('');
                var editor = new window.wangEditor('.textarea');
                editor.customConfig.menus = [
                    'head', // 标题
                    'bold', // 粗体
                    'italic', // 斜体
                    'underline', // 下划线
                    'strikeThrough', // 删除线
                    'foreColor', // 文字颜色
                    'backColor', // 背景颜色
                    'link', // 插入链接
                    'list', // 列表
                    'justify', // 对齐方式
                    'quote', // 引用
                    'image', // 插入图片
                    'table', // 表格
                    'undo', // 撤销
                    'redo' // 重复
                ]
                editor.customConfig.uploadImgShowBase64 = true;
                editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
                editor.customConfig.zIndex = 0;
                editor.customConfig.uploadImgServer = interface.textEditorImgUpdate;
                editor.customConfig.debug = location.href.indexOf('wangeditor_debug_mode=1') > 0;
                textareaData = editor;
                editor.create();
            }
        },

        /**
         * 页面函数:
         * statistics: 信息统计
         * newsList: 新闻管理
         * homeManagement: 软件管理
         * addGoods: 发布商品
         * goodsManagement: 管理商品
         * orderView: 订单查看
         * orderAudit: 退款审核
         * finance: 财务管理
         * userManagement: 用户管理
         */

        statistics: function () {
            if($('#echars').length>0){
                // 删除元素所有属性
                $.fn.attrAll = function () {
                    if (arguments.length === 0) {
                        if (this.length === 0) {
                            return null;
                        }
                        var obj = {};
                        $.each(this[0].attributes, function () {
                            if (this.specified) {
                                obj[this.name] = this.value;
                            }
                        });
                        return obj;
                    }
                    return old.apply(this, arguments);
                };
                // 使 Echars 兼容 Pjax
                $.each($('#echars').attrAll(), function (indexInArray, valueOfElement) {
                    if(indexInArray != 'id'){
                        $('#echars').removeAttr(indexInArray);
                    }
                });
                $('#echars').html('');

                var myChart = echarts.init(document.getElementById('echars'));
                myChart.showLoading();
                $.get(interface.statistics).done(function (data) {
                    /* 设置信息 */
                    $('#newsNum').html(data.newsNum);
                    $('#userNum').html(data.userNum);
                    $('#TodayWater').html(data.TodayWater);
                    $('#TodayProfit').html(data.TodayProfit);

                    myChart.hideLoading();
                    myChart.setOption({
                        title: {
                            text: '30天财务统计',
                            // x: 'center'
                        },
                        legend: {
                            data:['收入','支出'],
                            // x: 'left'
                        },
                        tooltip : {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'cross',
                                label: {
                                    backgroundColor: '#6a7985'
                                }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            data: ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30']
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [{
                            name: '收入',
                            data: data.echars.sr,
                            type: 'line'
                        },{
                            name: '支出',
                            data: data.echars.zc,
                            type: 'line'
                        }]
                    });
                });
            }
        },

        // 新闻管理
        newsList: function(){
            if ($('.newsList').length > 0) {
                nya.tableReset();
                var status = 'new', //判断是修改还是新增
                    editId; // 修改新闻的ID

                // 搜索
                $("#query").bind('keypress', function (event) {
                    if (event.keyCode == "13") {
                        search();
                    }
                });
                $("#search").click(function () {
                    search();
                });
                function search() {
                    $("#Table").dataTable({
                        url: interface.newsList.searchNews+"?search=" + encodeURI($("#query").val())
                    });
                }

                function _delNews(id){
                    $.ajax({
                        type: "post",
                        url: interface.newsList.delNews,
                        data: {
                            "delete":id
                        },
                        dataType: "json",
                        success: function (response) {
                            if(response == 0){
                                layer.msg('删除成功', { icon: 1 });
                                $('#Table').TableRefresh();
                            }else{
                                layer.msg('删除失败', { icon: 1 });
                            }
                        },
                        error: function(){
                            layer.msg('删除失败', { icon: 1 });
                        }
                    });
                }

                function _addnews(data, index){
                    $.ajax({
                        type: "post",
                        url: interface.newsList.addNews,
                        data: data,
                        dataType: "json",
                        success: function (response) {
                        	//如果返回的结果为0，表示成功，其他都是失败
                            if(response == 0){
                                layer.msg('添加成功');
                                $('#Table').TableRefresh();
                                layer.close(index);
                            }else{
                                layer.msg('添加失败');
                            }
                        },
                        error: function(){
                            layer.msg('添加失败');
                        }
                    });
                }

                $('#Table').dataTable({
                    url: interface.newsList.getNews,
                    debug: true,
                    serial: true,
                    check: true,
                    pageCapacity: 10,
                    loading: true,
                    align: 'center',
                    sign: false,
                    columns: [
                        {ColumnName: "id",title: "ID", width:100},
                        {ColumnName: "date",title: "发布时间"},
                        {ColumnName: "title",title: "标题"},
                        {title: "编辑",button: "edit",buttonName: "编辑",width: 100},
                        {title: "删除",button: "delete",buttonName: "删除",width: 100},
                    ],
                    editClick: function (row) {
                        status = 'edit';
                        editId = row.id;
                        $('.newsList #addNews').click()
                        $('.ttinput').val(row.title)
                        textareaData.txt.html(row.content) //设置内容
                    },
                    deleteClick: function (row) {
                        layer.confirm('确认删除新闻: '+row.title+'?', {
                            btn: ['删除', '取消'] //按钮
                        }, function () {
                            var delid  = [row.id]
                            _delNews(delid)
                        });
                    },
                    Click: function (row) {
                        console.log(row)
                    },
                })

                $('.newsList #addNews').click(function(){
                    var index = layer.open({
                        title:'发布新闻',
                        type: 1,
                        area: ['800px', '800px'],
                        move:'#LayWindow,.layui-layer-title',
                        moveOut : true,
                        content: '<div id="LayWindow"></div><div class="layerCon"><div class="addNews"><div class="newsTitle"><span class="tt">新闻标题:</span><input class="ttinput"type="text"></div><div class="textarea"></div><button class="submit">立即发送</button><div class="description"><h4>使用说明</h4><ul><li>使用说明金坷垃圣诞节快乐砂进口来的</li><li>加速度开始就爱看的沙经理可点击抗裂砂浆</li><li>啥借口了的骄傲删库了的时间阿卡丽</li><li>福克斯疯狂老师的减肥了开始的健康</li><li>加上考虑电视剧啊快乐的撒娇考虑</li></ul></div></div></div>',
                        success: function(layero, index){
                            nya.TEXTAREA();
                            $('.layerCon .submit').click(function (e) { 
                                e.preventDefault();
                                if(status == 'new'){ // 如果是新增新闻
                                    var title = $('.ttinput').val().trim();
                                    if(title != ''){
                                        var data = {
                                            "type":"new",
                                            "title": $('.ttinput').val(),
                                            "content": textareaData.txt.html()
                                        }
                                        _addnews(data, index);
                                    }else{
                                        layer.msg('请输入完整信息');
                                    }
                                }else if(status == 'edit'){ //如果是修改新闻
                                    status = 'new'
                                    var title = $('.ttinput').val().trim();
                                    if(title != ''){
                                        var data = {
                                            "type": "edit",
                                            "id": editId,
                                            "title": $('.ttinput').val(),
                                            "content": textareaData.txt.html()
                                        }
                                        _addnews(data, index);
                                    }else{
                                        layer.msg('请输入新闻标题');
                                    }
                                }
                            });
                        }
                    });
                })
                $('.newsList #delete').click(function () {
                    var tb = $('#Table').GetCheckArray(),
                        delArr = [];
                    $.each(tb, function (indexInArray, valueOfElement) { 
                        delArr.push(valueOfElement.id)
                    });
                    if(tb == null){
                        layer.msg('未选择数据');
                    }else{
                        layer.confirm('是否确认删除', {
                            btn: ['删除', '关闭'] 
                        }, function () {
                            _delNews(delArr);
                        });
                    }
                });
            }
        },

        // 医生展示
        doctors: function(){
            if ($('.doctors').length > 0) {
                nya.tableReset();
                var status = 'new', //判断是修改还是新增
                    editId; // 修改新闻的ID

                // 搜索
                $("#query").bind('keypress', function (event) {
                    if (event.keyCode == "13") {
                        search();
                    }
                });
                $("#search").click(function () {
                    search();
                });
                function search() {
                    $("#Table").dataTable({
                        url: interface.doctors.searchDoctor+"?search=" + encodeURI($("#query").val())
                    });
                }

                function _delDoctor(id){
                    $.ajax({
                        type: "post",
                        url: interface.doctors.deldoctors,
                        data: {
                            "delete":id
                        },
                        dataType: "json",
                        success: function (response) {
                            if(response== 0){
                                layer.msg('删除成功', { icon: 1 });
                                $('#Table').TableRefresh();
                            }else{
                                layer.msg('删除失败', { icon: 1 });
                            }
                        },
                        error: function(){
                            layer.msg('删除失败', { icon: 1 });
                        }
                    });
                }
        
                function _addDoctor(data, index){
                    $.ajax({
                        type: "post",
                        url: interface.doctors.adddoctors,
                        data: data,
                        dataType: "json",
                        processData : false, 
                        contentType : false,
                        success: function (response) {
                            if(response == 0){
                                layer.msg('添加成功');
                                $('#Table').TableRefresh();
                                layer.close(index);
                            }else{
                                layer.msg('添加失败');
                            }
                        },
                        error: function(){
                            layer.msg('添加失败');
                        }
                    });
                }

                $('#Table').dataTable({
                    url: interface.doctors.getDoctorList,
                    debug: true,
                    serial: true,
                    check: true,
                    pageCapacity: 10,
                    loading: true,
                    align: 'center',
                    sign: false,
                    columns: [
                        {ColumnName: "id",title: "ID", width:100},
                        {ColumnName: "img", img:true, title: "照片"},
                        {ColumnName: "name",title: "姓名"},
                        {ColumnName: "position",title: "职位"},
                        {title: "编辑",button: "edit",buttonName: "编辑",width: 100},
                        {title: "删除",button: "delete",buttonName: "删除",width: 100}, //自定义的按钮
                    ],
                    editClick: function (row) {//自定义按钮事件，事件名是上面设置的按钮名+Click
                        status = 'edit';
                        editId = row.id;
                        $('.doctors #addDoctors').click();
                        $('.l').css('background-image', 'url("'+row.img+'")');
                        $('.l i.icon-picture').remove();
                        $('#DoctorName').val(row.name);
                        $('#DoctorPosition').val(row.position);
                        textareaData.txt.html(row.info); //设置内容
                    },
                    deleteClick: function (row) {
                        layer.confirm('确认删除医生'+row.name, {
                            btn: ['删除', '取消'] //按钮
                        }, function () {
                            var delid  = [row.id];
                            _delDoctor(delid);
                        });
                    },
                    Click: function (row) {
                        console.log(row)
                    },

                })
                $('.doctors #addDoctors').click(function(){
                    //页面层
                    var index = layer.open({
                        title:'添加医生',
                        type: 1,
                        area: ['700px', '900px'], //宽高
                        move:'#LayWindow,.layui-layer-title',
                        moveOut : true,
                        content: '<div id="LayWindow"></div><div class="layerCon"><div class="addDoctors"><input id="dott" type="file"style="display:none;"name=""id=""><div class="l"title="上传图片"><i class="icon-picture"></i></div><div class="r"><div class="name"><span>姓名:</span><input id="DoctorName" type="text"></div><div class="position"><span>职位:</span><input id="DoctorPosition" type="text"></div></div><div class="textarea"></div><button class="submit">确认添加</button></div></div>',
                        success: function(layero, index){
                            $('.l').click(function (e) { 
                                e.preventDefault();
                                $('#dott').click();
                                $('#dott').change(function (e) { 
                                    e.preventDefault();
                                    var blobURL = window.URL.createObjectURL($('#dott')[0].files[0]);
                                    $('.l').css('background-image', 'url('+blobURL+')');
                                    $('.l i.icon-picture').remove();
                                });
                            });
                            nya.TEXTAREA()
                            $('.layerCon .submit').click(function (e) { 
                                e.preventDefault();
                                if(status == 'new'){
                                    console.log('新增')
                                    var name = $('#DoctorName').val().trim();
                                        position = $('#DoctorPosition').val().trim();
                                    if(name != '' && position != ''){
                                        var data = {
                                            "type":"new",
                                            "name": $('#DoctorName').val(),
                                            "position": $('#DoctorPosition').val(),
                                            "info": textareaData.txt.html(),
                                            "img": $('#dott')[0].files[0]
                                        }
                                        var formData = new FormData();
                                        formData.append('type','new');
                                        formData.append('name',$('#DoctorName').val());
                                        formData.append('position',$('#DoctorPosition').val());
                                        formData.append('info',textareaData.txt.html());
                                        formData.append('img',$('#dott')[0].files[0]);
                                        _addDoctor(formData, index);
                                    }else{
                                        layer.msg('请输入完整信息');
                                    }
                                }else if(status == 'edit'){
                                    status = 'new';
                                    var name = $('#DoctorName').val().trim();
                                        position = $('#DoctorPosition').val().trim();
                                    if(name != '' && position != ''){
                                        var data = {
                                            "type": "edit",
                                            "id": editId,
                                            "name": $('#DoctorName').val(),
                                            "position": $('#DoctorPosition').val(),
                                            "info": textareaData.txt.html(),
                                            "img": $('#dott')[0].files[0]
                                        }
                                        var formData = new FormData();
                                        formData.append('type','edit');
                                        formData.append('id',editId)
                                        formData.append('name',$('#DoctorName').val());
                                        formData.append('position',$('#DoctorPosition').val());
                                        formData.append('info',textareaData.txt.html());
                                        formData.append('img',$('#dott')[0].files[0]);
                                        _addDoctor(formData, index);
                                    }else{
                                        layer.msg('请输入完整信息');
                                    }
                                }
                            });
                        }
                    });
                })
                $('.doctors #delete').click(function () {
                    var tb = $('#Table').GetCheckArray(),
                        delArr = [];
                    $.each(tb, function (indexInArray, valueOfElement) { 
                        delArr.push(valueOfElement.id)
                    });
                    if(tb == null){
                        layer.msg('未选择数据');
                    }else{
                        layer.confirm('是否确认删除', {
                            btn: ['删除', '关闭'] 
                        }, function () {
                            _delDoctor(delArr);
                        });
                    }
                });
            }
        },

        // 轮播图管理
        homeManagement: function () {
            if ($('.homeManagement').length > 0) {
                nya.tableReset();
                var status = 'new', //判断是修改还是新增
                    editId; // 修改新闻的ID

                function _delImg(id){
                    $.ajax({
                        type: "post",
                        url: interface.homeManagement.delImg,
                        data: {
                            "delete":id
                        },
                        dataType: "json",
                        success: function (response) {
                            if(response== 0){
                                layer.msg('删除成功', { icon: 1 });
                                $('#Table').TableRefresh();
                            }else{
                                layer.msg('删除失败', { icon: 1 });
                            }
                        },
                        error: function(){
                            layer.msg('删除失败', { icon: 1 });
                        }
                    });
                }
        
                function _addImg(data, index){
                    $.ajax({
                        type: "post",
                        url: interface.homeManagement.addImg,
                        data: data,
                        dataType: "json",
                        processData : false, 
                        contentType : false,
                        success: function (response) {
                            if(response == 0){
                                layer.msg('添加成功');
                                $('#Table').TableRefresh();
                                layer.close(index);
                            }else{
                                layer.msg('添加失败');
                            }
                        },
                        error: function(){
                            layer.msg('添加失败');
                        }
                    });
                }

                $('#Table').dataTable({
                    url: interface.homeManagement.getImg,
                    debug: true,
                    serial: true,
                    check: true,
                    pageCapacity: 10,
                    loading: true,
                    align: 'center',
                    sign: false,
                    columns: [
                        {ColumnName: "id",title: "ID", width:100},
                        {ColumnName: "title",title: "标题"},
                        {ColumnName: "img",img:true, title: "图片"},
                        {ColumnName: "url",title: "链接"},
                        {title: "编辑",button: "edit",buttonName: "编辑",width: 100},
                        {title: "删除",button: "delete",buttonName: "删除",width: 100}, //自定义的按钮
                    ],
                    editClick: function (row) {//自定义按钮事件，事件名是上面设置的按钮名+Click
                        status = 'edit'
                        editId = row.id;
                        $('.homeManagement #addImg').click()
                        $('.l').css('background-image', 'url("'+row.img+'")');
                        $('.l i.icon-picture').remove();
                        $('#imgTitle').val(row.title)
                        $('#imgLinks').val(row.url)
                    },
                    deleteClick: function (row) {
                        layer.confirm('确认删除图片'+row.title, {
                            btn: ['删除', '取消'] //按钮
                        }, function () {
                            var delid  = [row.id];
                            _delImg(delid);
                        });
                    },
                    Click: function (row) {
                        console.log(row)
                    },

                })
                $('.homeManagement #addImg').click(function(){
                    //页面层
                    var index = layer.open({
                        title:'添加轮播图',
                        type: 1,
                        area: ['700px', '550px'], //宽高
                        move:'#LayWindow,.layui-layer-title',
                        moveOut : true,
                        content: '<div id="LayWindow"></div><div class="layerCon"><div class="addImages"><input type="file"style="display:none;"name=""id="dott"><div class="l"title="上传图片"><i class="icon-picture"></i></div><div class="r"><div class="name"><span>标题:</span><input id="imgTitle"type="text"></div><div class="position"><span>链接:</span><input id="imgLinks"type="text"></div></div><button class="submit">确认添加</button></div></div>',
                        success: function(layero, index){
                            $('.l').click(function (e) { 
                                e.preventDefault();
                                $('#dott').click();
                                $('#dott').change(function (e) { 
                                    e.preventDefault();
                                    var blobURL = window.URL.createObjectURL($('#dott')[0].files[0]);
                                    $('.l').css('background-image', 'url('+blobURL+')');
                                    $('.l i.icon-picture').remove();
                                });
                            });
                            $('.layerCon .submit').click(function (e) { 
                                e.preventDefault();
                                var title = $('#imgTitle').val().trim();
                                    links = $('#imgLinks').val().trim();
                              if(status == 'new'){
                                    if(title != ''){
                                        var data = {
                                            "type":"new",
                                            "title": title,
                                            "img": $('#dott')[0].files[0],
                                            "url": links
                                        }
                                        var formData = new FormData();
                                        formData.append('type','new');
                                        formData.append('title',title);
                                        formData.append('img',$('#dott')[0].files[0]);
                                        formData.append('url',links);
                                        _addImg(formData,index)
                                    }else{
                                        layer.msg('请输入完整信息');
                                    }
                                }else if(status == 'edit'){
                                    status = 'new';
                                    var title = $('#imgTitle').val().trim();
                                        links = $('#imgLinks').val().trim();
                                    if(title != ''){
                                        var data = {
                                            "type":"new",
                                            "id": editId,
                                            "title": title,
                                            "img": $('#dott')[0].files[0],
                                            "url": links
                                        }
                                        var formData = new FormData();
                                        formData.append('type','new');
                                        formData.append('id',editId);
                                        formData.append('title',title);
                                        formData.append('img',$('#dott')[0].files[0]);
                                        formData.append('url',links);
                                        _addImg(formData,index)
                                    }else{
                                        layer.msg('请输入完整信息');
                                    }
                                }
                            });
                        }
                    });
                })
                $('.homeManagement #delete').click(function () {
                    var tb = $('#Table').GetCheckArray(),
                        delArr = [];
                    $.each(tb, function (indexInArray, valueOfElement) { 
                        delArr.push(valueOfElement.id)
                    });
                    if(tb == null){
                        layer.msg('未选择数据');
                    }else{
                        layer.confirm('是否确认删除', {
                            btn: ['删除', '关闭'] 
                        }, function () {
                            _delImg(delArr);
                        });
                    }
                });
            }
        },

        // 信息介绍
        infoList: function(){
            if ($('.infoList').length > 0) {
                nya.tableReset();
                var status = 'new', //判断是修改还是新增
                    editId; // 修改新闻的ID

                // 搜索
                $("#query").bind('keypress', function (event) {
                    if (event.keyCode == "13") {
                        search();
                    }
                });
                $("#search").click(function () {
                    search();
                });
                function search() {
                    $("#Table").dataTable({
                        url: interface.infoList.searchInfo+"?search=" + encodeURI($("#query").val())
                    });
                }
        
                function _delInfo(id){
                    $.ajax({
                        type: "post",
                        url: interface.infoList.delInfo,
                        data: {
                            "delete":id
                        },
                        dataType: "json",
                        success: function (response) {
                            if(response.error == 0){
                                layer.msg('删除成功', { icon: 1 });
                                $('#Table').TableRefresh();
                            }else{
                                layer.msg('删除失败', { icon: 1 });
                            }
                        },
                        error: function(){
                            layer.msg('删除失败', { icon: 1 });
                        }
                    });
                }
        
                function _addInfo(data, index){
                    $.ajax({
                        type: "post",
                        url: interface.infoList.addInfo,
                        data: data,
                        dataType: "json",
                        processData : false, 
                        contentType : false,
                        success: function (response) {
                            if(response.error == 0){
                                layer.msg('添加成功');
                                $('#Table').TableRefresh();
                                layer.close(index);
                            }else{
                                layer.msg('添加失败');
                            }
                        },
                        error: function(){
                            layer.msg('添加失败');
                        }
                    });
                }

                $('#Table').dataTable({
                    url: interface.infoList.getInfo,
                    debug: true,
                    serial: true,
                    check: true,
                    pageCapacity: 10,
                    loading: true,
                    align: 'center',
                    sign: false,
                    columns: [
                        {ColumnName: "id",title: "ID", width:100},
                        {ColumnName: "img",img:true, title: "图片"},
                        {ColumnName: "date",title: "发布时间"},
                        {ColumnName: "title",title: "标题"},
                        {title: "编辑",button: "edit",buttonName: "编辑",width: 100},
                        {title: "删除",button: "delete",buttonName: "删除",width: 100},
                    ],
                    editClick: function (row) {
                        status = 'edit';
                        editId = row.id;
                        $('.infoList #addInfo').click()
                        $('.l').css('background-image', 'url("'+row.img+'")');
                        $('.l i.icon-picture').remove();
                        $('#infoTitle').val(row.title)
                        textareaData.txt.html(row.content) //设置内容
                    },
                    deleteClick: function (row) {
                        layer.confirm('确认删除新闻: '+row.title+'?', {
                            btn: ['删除', '取消'] //按钮
                        }, function () {
                            var delid  = [row.id];
					        _delInfo(delid);
                            layer.msg('删除成功', { icon: 1 });
                        });
                    },
                    Click: function (row) {
                        console.log(row)
                    },
                })

                $('.infoList #addInfo').click(function(){
                    var index = layer.open({
                        title:'添加介绍',
                        type: 1,
                        area: ['700px', '820px'], //宽高
                        move:'#LayWindow,.layui-layer-title',
                        moveOut : true,
                        content: '<div id="LayWindow"></div><div class="layerCon"><div class="addInfo"><input id="dott" type="file"style="display:none;"name=""id=""><div class="l"title="上传图片"><i class="icon-picture"></i></div><div class="r"><div class="name"><span>标题:</span><input id="infoTitle" type="text"></div></div><div class="textarea"></div><button class="submit">确认添加</button></div></div>',
                        success: function(layero, index){
                            $('.l').click(function (e) { 
                                e.preventDefault();
                                $('#dott').click();
                                $('#dott').change(function (e) { 
                                    e.preventDefault();
                                    var blobURL = window.URL.createObjectURL($('#dott')[0].files[0]);
                                    $('.l').css('background-image', 'url('+blobURL+')');
                                    $('.l i.icon-picture').remove();
                                });
                            });
                            nya.TEXTAREA()
                            $('.layerCon .submit').click(function (e) { 
                                e.preventDefault();
                                var title = $('#infoTitle').val().trim();
                                if(status == 'new'){
                                    console.log('新增')
                                    if(title != ''){
                                        var data = {
                                            "type":"new",
                                            "img": $('#dott')[0].files[0],
                                            "title": title,
                                            "content": textareaData.txt.html()
                                        }
                                        var formData = new FormData();
                                        formData.append("type",'new');
                                        formData.append("img",$('#dott')[0].files[0]);
                                        formData.append("title",title);
                                        formData.append("content",textareaData.txt.html());
                                        _addInfo(formData, index);
                                    }else{
                                        layer.msg('请输入完整信息');
                                    }
                                }else if(status == 'edit'){
                                    console.log('修改')
                                    status = 'new';
                                    if(title != ''){
                                        var data = {
                                            "type":"edit",
                                            "id": editId,
                                            "img": $('#dott')[0].files[0],
                                            "title": title,
                                            "content": textareaData.txt.html()
                                        }
                                        var formData = new FormData();
                                        formData.append("type",'edit');
                                        formData.append("id",editId);
                                        formData.append("img",$('#dott')[0].files[0]);
                                        formData.append("title",title);
                                        formData.append("content",textareaData.txt.html());
                                        _addInfo(formData, index);
                                    }else{
                                        layer.msg('请输入完整信息');
                                    }
                                }
                            });
                        }
                    });
                })
                $('.infoList #delete').click(function () {
                    var tb = $('#Table').GetCheckArray(),
                        delArr = [];
                    $.each(tb, function (indexInArray, valueOfElement) { 
                        delArr.push(valueOfElement.id)
                    });
                    if(tb == null){
                        layer.msg('未选择数据');
                    }else{
                        layer.confirm('是否确认删除', {
                            btn: ['删除', '关闭'] 
                        }, function () {
                            _delInfo(delArr);
                        });
                    }
                });
            }
        },

        // 添加商品
        addGoods: function () {
            // 用于存储图片链接
            var goodsImgArr = [];
            var editGoodsId;
            // 下拉菜单是否选中
            $.fn.ischecked = function () {
                if (this.css('display') != 'none') {
                    if (this.find('.rel').text() == '请选择') {
                        this.find('.click_area').css('border-color', '#FF5252');
                        return false;
                    } else {
                        this.find('.click_area').css('border-color', '#c4c4c6');
                        return true;
                    }
                }
            }
            // 是否为空
            $.fn.inputNull = function(){
                if($.trim(this.val()) == ''){
                    this.val('');
                    this.css('border-color','#FF5252');
                    return false;
                }else{
                    this.attr('style','');
                    return true;
                }
            }

            $('#goodsContent input').focus(function (e) { 
                e.preventDefault();
                $(this).css('border-color', '#c4c4c6');
            });

            $(".zxx_v_menu").click(function () {
                var text = $(this);
                $(this).find('.v_menu_list li').click(function (e) {
                    e.preventDefault();
                    $(text).find('.rel').text($(this).text());
                    // $('.zxx_v_menu').show();
                });

                if ($(this).find('.rel').text() != '请选择') {
                    $(this).find('.click_area').css('color', '#606266');
                    $(this).find('.click_area').css('border-color', '#c4c4c6');
                }

                if ($(this).find('.v_menu_list').css('display') == 'none') {
                    $(this).find('i.icon-arrow-down').css('transform', 'rotate(180deg)');
                } else {
                    $(this).find('i.icon-arrow-down').css('transform', 'rotate(0deg)');
                }
                $(this).find('.vMenuList').slideToggle(250);
                return false;
            });

            $('#easyContainer').easyUpload({
                allowFileTypes: '*.jpg;*.png;*.gif;*.jpeg', //允许上传文件类型，格式';*.doc;*.pdf'
                allowFileSize: 100000, //允许上传文件大小(KB)
                selectText: '选择文件', //选择文件按钮文案
                multi: true, //是否允许多文件上传
                multiNum: 5, //多文件上传时允许的文件数
                showNote: true, //是否展示文件上传说明
                note: '提示：最多上传5个文件，支持格式为jpg、png、gif、jpeg', //文件上传说明
                showPreview: true, //是否显示文件预览
                url: interface.addGoods.imgUpload, //上传文件地址
                fileName: 'file', //文件filename配置参数
                // formParam: {
                    //token: $.cookie('token_cookie')//不需要验证token时可以去掉
                // }, //文件filename以外的配置参数，格式：{key1:value1,key2:value2}
                timeout: 30000, //请求超时时间
                okCode: 200, //与后端返回数据code值一致时执行成功回调，不配置默认200
                successFunc: function (res) {
                    console.log('成功回调', res);
                    goodsImgArr = res
                }, //上传成功回调函数
                errorFunc: function (res) {
                    console.log('失败回调', res);
                }, //上传失败回调函数
                deleteFunc: function (res) {
                    console.log('删除回调', res);
                } //删除文件回调函数
            });

            $('.addGoodsBtn').click(function (e) { 
                e.preventDefault();
                if($('#one-level').ischecked() & $('#two-level').ischecked() & $('#dddtitle').inputNull() & $('#dddprice').inputNull() & $('#ddddiscount').inputNull()){
                    var className = $('#good-parentCategory').text(),
                        title = $('#dddtitle').val(),
                        price = $('#dddprice').val(),
                        discount = $('#ddddiscount').val(),
                        data;
                        if(editGoodsId != undefined){
                            console.log('修改')
                            data = {
                                "editId": 3458,
                                "className": className,
                                "title": title,
                                "price": price,
                                "discount": discount,
                                "content": textareaData.txt.html()
                            };
                        }else{
                            console.log('添加')
                            data = {
                                "className": className,
                                "title": title,
                                "price": price,
                                "discount": discount,
                                "content": textareaData.txt.html()
                            }
                        }
                        $.ajax({
                            type: "post",
                            url: interface.addGoods.addGoods,
                            data: data,
                            dataType: "json",
                            success: function (response) {
                                if(response.error == 0){
                                    if(editGoodsId != undefined){
                                        layer.msg('修改成功');
                                        editGoodsId = undefined;
                                    }else{
                                        layer.msg('添加成功');
                                    }
                                    setTimeout(function(){
                                        window.location.reload;
                                    },2000)
                                }else{
                                    layer.msg('添加失败');
                                }
                            },
                            error: function(response){
                                layer.msg('添加失败');
                            }
                        });
                }else{
                    layer.msg('请输入完整数据')
                }
            });

            // 判断是否是编辑
            if(localStorage.getItem('editId') != null){
                editGoodsId = localStorage.getItem('editId');
                localStorage.removeItem('editId');
                $.ajax({
                    type: "get",
                    url: interface.addGoods.getGoods+'&goodsid='+editGoodsId,
                    dataType: "json",
                    success: function (response) {
                        // var img = response.img;
                        // $.each(img, function (indexInArray, valueOfElement) { 
                        //     var reg = /([^<>/\\\|:""\*\?]+)\.\w+$/ig;
                        //     $('.easy_upload_queue').append('<li class="easy_upload_queue_item" data-index="0"><div class="easy_upload_preview queue_item-section"><img class="easy_upload_img" src="'+img[indexInArray]+'"></div><div class="easy_upload_file1 queue_item-section"><p class="easy_upload_filename">'+img[indexInArray].match(reg)+'</p><p class="easy_upload_progress"><span class="easy_upload_bar"></span></p></div><div class="easy_upload_file2 queue_item-section"><p class="easy_upload_fiesize">437.86KB</p><p class="easy_upload_percent">0%</p></div><div class="easy_upload_status queue_item-section"><p class="status status1">可以上传</p><p class="status status2">等待上传</p><p class="status status3">上传中</p><p class="status status4">上传失败</p><p class="status status5">上传成功</p></div><div class="easy_upload_btn queue_item-section"><p class="easy_upload_upbtn btn noselect">上传</p><p class="easy_upload_delbtn btn noselect">删除</p></div><div class="easy_upload_checkone queue_item-section"><i class="easyUploadIcon noselect queue_check queue_check_allow_true" data-checked="no" data-up="1">&#xe693;</i></div></li>'); 
                        // });
                        $('#good-parentCategory').html(response.className);
                        $('#good-parentCategory').css({
                            'color': 'rgb(96, 98, 102)',
                            'border-color': 'rgb(196, 196, 198)'
                        });
                        $('.xTitle:first-child').append('(编辑商品禁止修改图片)');
                        $('#easyContainer').remove();
                        $('.admin-body > .title').append('(编辑商品: '+editGoodsId+')');
                        $('#dddtitle').val(response.title);
                        $('#dddprice').val(response.price);
                        $('#ddddiscount').val(response.discount);
                        textareaData.txt.html(response.content);
                    },
                    error: function(){
                        layer.msg('后台请求出错')
                    }
                });
            }
        },

        goodsManagement: function () {
            if ($('.goodsManagement').length > 0) {
                nya.tableReset();

                // 搜索
                $("#query").bind('keypress', function (event) {
                    if (event.keyCode == "13") {
                        search();
                    }
                });
                $("#search").click(function () {
                    search();
                });
                function search() {
                    $("#Table").dataTable({
                        url: interface.goodsManagement.searchGoods+"?search=" + encodeURI($("#query").val())
                    });
                }

                function _delGoods(id){
                    $.ajax({
                        type: "post",
                        url: interface.goodsManagement.delGoods,
                        data: {
                            "delete":id
                        },
                      
                        dataType: "json",
                        success: function (response) {
                            if(response.error == 0){
                                layer.msg('删除成功', { icon: 1 });
                                $('#Table').TableRefresh();
                            }else{
                                layer.msg('删除失败', { icon: 1 });
                            }
                        },
                        error: function(){
                            layer.msg('删除失败', { icon: 1 });
                        }
                    });
                }

                $('#Table').dataTable({
                    url: interface.goodsManagement.getGoods,
                    debug: true,
                    serial: true,
                    check: true,
                    pageCapacity: 10,
                    loading: true,
                    align: 'center',
                    sign: false,
                    columns: [
                        {ColumnName: "id",title: "ID", width:100},
                        {ColumnName: "class",title: "分类"},
                        {ColumnName: "title",title: "标题"},
                        {ColumnName: "price",title: "价格"},
                        {ColumnName: "discount",title: "折扣价"},
                        {ColumnName: "transaction",title: "交易数量"},
                        {title: "编辑",button: "edit",buttonName: "编辑",width: 100}, //自定义的按钮
                        {title: "删除",button: "delete",buttonName: "删除",width: 100}, //自定义的按钮
                    ],
                    deleteClick: function (row) {
                        layer.confirm('确认删除商品'+row.id, {
                            btn: ['删除', '取消'] //按钮
                        }, function () {
                            var delid  = [row.id];
                            _delGoods(delid);
                        });
                    },
                    editClick: function (row) {
                        localStorage.setItem('editId',row.id);
                        $('#addGoods').click();
                    },
                    Click: function (row) {
                        console.log(row)
                    },

                })
                $('.goodsManagement #delete').click(function () {
                    var tb = $('#Table').GetCheckArray(),
                        delArr = [];
                    $.each(tb, function (indexInArray, valueOfElement) { 
                        delArr.push(valueOfElement.id)
                    });
                    if(tb == null){
                        layer.msg('未选择数据');
                    }else{
                        layer.confirm('是否确认删除', {
                            btn: ['删除', '关闭'] 
                        }, function () {
                            _delGoods(delArr);
                        });
                    }
                });
            }
        },

        orderView: function () {
            if ($('.orderView').length > 0) {
                nya.tableReset();
                var getOrder = interface.orderView.getOrder;
                if(localStorage.getItem('searchData') != null){
                    getOrder = interface.orderView.searchOrder+"?search=" + encodeURI(localStorage.getItem('searchData'));
                    localStorage.removeItem('searchData')
                }

                // 搜索
                $("#query").bind('keypress', function (event) {
                    if (event.keyCode == "13") {
                        search();
                    }
                });
                $("#search").click(function () {
                    search();
                });
                function search() {
                    $("#Table").dataTable({
                        url: interface.orderView.searchOrder+"?search=" + encodeURI($("#query").val())
                    });
                }

                $('#Table').dataTable({
                    url: getOrder,
                    debug: true,
                    serial: true,
                    // check: true,
                    pageCapacity: 10,
                    loading: true,
                    align: 'center',
                    sign: false,
                    columns: [
                        {ColumnName: "id",title: "订单号", width:250},
                        {ColumnName: "date",title: "时间"},
                        {ColumnName: "weChatId",title: "微信号"},
                        {ColumnName: "title",title: "标题"},
                        {ColumnName: "price",title: "价格"},
                        {ColumnName: "status",title: "状态"},
                    ],
                    Click: function (row) {
                        console.log(row)
                    },
                })
            }
        },

        orderAudit: function () {
            if ($('.orderAudit').length > 0) {
                nya.tableReset();

                // 搜索
                $("#query").bind('keypress', function (event) {
                    if (event.keyCode == "13") {
                        search();
                    }
                });
                $("#search").click(function () {
                    search();
                });
                function search() {
                    $("#Table").dataTable({
                        url: interface.orderAudit.searchOrder+"?search=" + encodeURI($("#query").val())
                    });
                }

                $('#Table').dataTable({
                    url: interface.orderAudit.getOrder,
                    debug: true,
                    serial: true,
                    // check: true,
                    pageCapacity: 10,
                    loading: true,
                    align: 'center',
                    sign: false,
                    columns: [
                        {ColumnName: "id",title: "ID", width:100},
                        {ColumnName: "date",title: "时间"},
                        {ColumnName: "weChatId",title: "微信号"},
                        {ColumnName: "title",title: "标题"},
                        {ColumnName: "price",title: "价格"},
                        {title: "编辑",button: "edit",buttonName: "审核",width: 100},
                    ],
                    editClick: function (row) {//自定义按钮事件，事件名是上面设置的按钮名+Click
                        console.log("自定义编辑："+row.id);
                        layer.confirm('审核退款: '+row.id, {
                            title: '审核退款',
                            btn: ['通过', '拒绝'] //按钮
                        }, function () {
                            layer.confirm('是否允许订单'+row.id+'退款', {
                                title: '请确认',
                                btn: ['确定', '取消'] //按钮
                            }, function () {
                                $.ajax({
                                    type: "post",
                                    url: interface.orderAudit.audit,
                                    data: {
                                        "type":"allow",
                                        "id":row.id
                                    },
                                    dataType: "json",
                                    success: function (response) {
                                        if(response.error == 0){
                                            layer.msg('已审核退款: '+row.id, { icon: 1 });
                                        }else{
                                            layer.msg('审核失败, 后台拒绝')
                                        }
                                    },
                                    error: function(){
                                        layer.msg('审核失败, 后台错误');
                                    }
                                });
                            });
                        }, function () {
                            layer.prompt({ title: '请输入拒绝原因', formType: 2}, function (pass, index) {
                                $.ajax({
                                    type: "post",
                                    url: interface.orderAudit.audit,
                                    data: {
                                        "type":"refuse",
                                        "id":row.id,
                                        "reason": pass
                                    },
                                    dataType: "json",
                                    success: function (response) {
                                        if(response.error == 0){
                                            layer.msg('拒绝成功: '+row.id, { icon: 1 });
                                            layer.close(index);
                                        }else{
                                            layer.msg('审核失败, 后台拒绝')
                                        }
                                    },
                                    error: function(){
                                        layer.msg('审核失败, 后台错误');
                                    }
                                });
                            });
                        });
                    },
                    Click: function (row) {
                        console.log(row)
                    },
                })
            }
        },

        // 财务管理
        finance: function () {
            if ($('.finance').length > 0) {
                nya.tableReset();

                $.ajax({
                    type: "get",
                    url: interface.finance.statistics,
                    dataType: "json",
                    success: function (response) {
                        $('#income').html(response.totalRevenue);
                        $('#expenditure').html(response.totalExpenses);
                        $('#profit').html(response.totalProfit);
                    },
                    error: function(){
                        layer.msg('后台请求出错')
                    }
                });

                // 搜索
                $("#query").bind('keypress', function (event) {
                    if (event.keyCode == "13") {
                        search();
                    }
                });
                $("#search").click(function () {
                    search();
                });
                function search() {
                    $("#Table").dataTable({
                        url: interface.finance.searchFinance+"?search=" + encodeURI($("#query").val())
                    });
                }

                $('#Table').dataTable({
                    url: interface.finance.getFinance,
                    debug: true,
                    serial: true,
                    // check: true,
                    pageCapacity: 10,
                    loading: true,
                    align: 'center',
                    sign: false,
                    columns: [
                        {ColumnName: "id",title: "订单号", width:350},
                        {ColumnName: "class",title: "标题"},
                        {ColumnName: "amount",title: "金额"},
                    ],
                    Click: function (row) {
                        console.log(row)
                        $('#orderView').click();
                        localStorage.setItem('searchData',row.id);
                    }
                })
                $('#output').click(function (e) { 
                    e.preventDefault();
                    $.ajax({
                        type: "get",
                        url: "/json/finance.json",
                        dataType: "json",
                        success: function (response) {
                            nya.JSONToCSVConvertor(response.rows,'财务表')
                        }
                    });
                });
            }
        },

        userManagement: function () {
            if ($('.userManagement').length > 0) {
                nya.tableReset();

                // 搜索
                $("#query").bind('keypress', function (event) {
                    if (event.keyCode == "13") {
                        search();
                    }
                });
                $("#search").click(function () {
                    search();
                });
                function search() {
                    $("#Table").dataTable({
                        url: interface.userManagement.searchUser+"?search=" + encodeURI($("#query").val())
                    });
                }

                $('#Table').dataTable({
                    url: interface.userManagement.getUser,
                    debug: true,
                    serial: true,
                    // check: true,
                    pageCapacity: 10,
                    loading: true,
                    align: 'center',
                    sign: false,
                    columns: [
                        {ColumnName: "id",title: "ID",width: 200},
                        {ColumnName: "phoneNumber",title: "手机号",width: 250},
                        {ColumnName: "WeChatId",title: "微信号"},
                        {title: "查看",button: "show",buttonName: "查看订单",width: 150}, //自定义的按钮
                    ],
                    showClick: function (row,mm) {//自定义按钮事件，事件名是上面设置的按钮名+Click
                        console.log(mm)
                        var idd = 'mkl'+~~(Math.random()*1000);
                        console.log(idd)
                        var index = layer.open({
                            title:'查看订单',
                            type: 1,
                            area: ['850px', '600px'], //宽高
                            move:'#LayWindow,.layui-layer-title',
                            moveOut : true,
                            content: '<div id="LayWindow"></div><div class="layerCon"><div class="orderList"><table id='+idd+'></table></div></div>',
                            success: function(){
                                $('#'+idd).dataTable({
                                    url: interface.userManagement.getUserOrderList+'?userid='+row.id,
                                    debug: true,
                                    serial: true,
                                    pageCapacity: 10,
                                    loading: true,
                                    align: 'center',
                                    sign: false,
                                    columns: [
                                        {ColumnName: "id",title: "订单号",width: 200},
                                        {ColumnName: "date",title: "时间",width: 250},
                                        {ColumnName: "title",title: "商品标题"},
                                        {ColumnName: "status",title: "交易成功"},
                                        {ColumnName: "amount",title: "交易金额"},
                                    ],
                                    Click: function (row) {
                                        console.log(row)
                                    },
                                })
                            }
                        })
                    },
                    Click: function (row) {
                        console.log(row)
                    },

                })
                $('.userManagement #sendMessage').click(function (e) {
                    e.preventDefault();
                    //页面层
                    var index = layer.open({
                        title:'发布新闻',
                        type: 1,
                        area: ['800px', '800px'], //宽高
                        move:'#LayWindow,.layui-layer-title',
                        moveOut : true,
                        content: '<div id="LayWindow"></div><div class="layerCon"><div class="addNews"><div class="newsTitle"><span class="tt">信息标题:</span><input class="ttinput"type="text"></div><div class="textarea"></div><button class="submit">立即发送</button><div class="description"><h4>使用说明</h4><ul><li>使用说明金坷垃圣诞节快乐砂进口来的</li><li>加速度开始就爱看的沙经理可点击抗裂砂浆</li><li>啥借口了的骄傲删库了的时间阿卡丽</li><li>福克斯疯狂老师的减肥了开始的健康</li><li>加上考虑电视剧啊快乐的撒娇考虑</li></ul></div></div></div>',
                        success: function(layero, index){
                            nya.TEXTAREA()
                            $('.layerCon .submit').click(function (e) { 
                                e.preventDefault();
                                var title = $('.ttinput').val().trim();
                                if(title != ''){
                                    $.ajax({
                                        type: "post",
                                        url: interface.userManagement.sendMessage,
                                        data: {
                                            "title":title,
                                            "content": textareaData.txt.html()
                                        },
                                        dataType: "json",
                                        success: function (response) {
                                            if(response.error == 0){
                                                layer.msg('发送成功');
                                                layer.close(index);
                                            }else{
                                                layer.msg('后台拒绝请求');
                                            }
                                        },
                                        error: function(){
                                            layer.msg('后台请求错误');
                                        }
                                    });
                                }else{
                                    layer.msg('请输入新闻标题');
                                }
                            });
                        }
                    });
                })
            }
        },

    }

$(function () {
    // ADMIN
    nya.ADMIN();
    // PJAX
    nya.PJAX();
    // 首次加载动画
    nya.LOADING();
    // 侧边栏
    nya.SIDEBAR();
    // 头部菜单
    nya.HEADERBAR();
    // 编辑器
    nya.TEXTAREA();
    // sidebar选择
    nya.SIDEBARHOVER();
    // 信息统计
    nya.statistics();
    // 新闻管理
    nya.newsList();
    // 首页管理
    nya.homeManagement();
    // 医生展示
    nya.doctors();
    // 医院介绍
    nya.infoList();
    // 发布商品
    nya.addGoods();
    // 商品管理
    nya.goodsManagement();
    // 订单查看
    nya.orderView();
    // 退款审核
    nya.orderAudit();
    // 财务管理
    nya.finance();
    // 用户管理
    nya.userManagement();
})